<!--
 * @Description: 
 * @Autor: zhangbing
 * @Date: 2021-07-30 19:12:07
 * @LastEditors: zhangbing
 * @LastEditTime: 2021-07-31 13:12:36
-->

<template>
  <div>
    <city-header />
    <city-search :cities="citiesData"/>
    <city-list :cities="citiesData" :hot="hotCitiesData" :letter="letter"/>
    <city-alphabet :cities="citiesData" @change="handleLetterChange" />
  </div>
</template>

<script>
import CityHeader from "./components/Header.vue";
import CitySearch from "./components/Search.vue";
import CityList from "./components/List.vue";
import CityAlphabet from "./components/Alphabet.vue";

import axios from "axios";

import cityData from "../../../public/mock/city.json";

export default {
  name: "City",
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet,
  },
  data() {
    return {
      citiesData: cityData.data.cities,
      hotCitiesData: cityData.data.hotCities,
      letter: "",
    };
  },
  created() {},
  mounted() {
    console.log(this.citiesData);
    console.log(this.hotCitiesData);
    this.getCityInfo();
  },
  methods: {
    handleLetterChange(letter) {
      this.letter = letter;
      console.log(this.letter);
    },
    getCityInfo() {
      axios.get("/api/city.json").then(this.handleGetCityInfoSuccd);
    },
    handleGetCityInfoSuccd(res) {
      console.log(res);
      res = res.data;
      if (res.ret && res.data) {
        const data = res.data;
        this.cities = data.cities;
        this.hotCities = data.hotCities;
      }
    },
  },
};
</script>

<style lang="stylus" scoped></style>

